package day6;
import uk.ac.shef.wit.simmetrics.similaritymetrics.*;
public class Jaro
{
    private String compOne;
    private String compTwo;
 
    private String theMatchA = "";
    private String theMatchB = "";
    private int mRange = -1;
    private JaroWinkler jaro;
    
    public Jaro()
    {
    }
     
    public Jaro(String s1, String s2)
    {
        compOne = s1;
        compTwo = s2;
        jaro = new JaroWinkler();
    }
 
    public double getSimilarity(String s1, String s2)
    {
    	double similarity = jaro.getSimilarity(s1, s2);
    	return similarity;
    }
 
    private int getMatch()
    {
         
        theMatchA = "";
        theMatchB = "";
         
        int matches = 0;
 
        for (int i = 0; i < compOne.length(); i++)
        {
            //Look backward
            int counter = 0;
            while(counter <= mRange && i >= 0 && counter <= i)
            {
                if (compOne.charAt(i) == compTwo.charAt(i - counter))
                {
                    matches++;
                    theMatchA = theMatchA + compOne.charAt(i);
                    theMatchB = theMatchB + compTwo.charAt(i);
                }
                counter++;                
            }
 
            //Look forward
            counter = 1;
            while(counter <= mRange && i < compTwo.length() && counter + i < compTwo.length())
            {
                if (compOne.charAt(i) == compTwo.charAt(i + counter))
                {
                    matches++;
                    theMatchA = theMatchA + compOne.charAt(i);
                    theMatchB = theMatchB + compTwo.charAt(i);
                }
                counter++;
            }
        }
        return matches;
    }
 
    private int getMissMatch(String s1, String s2)
    {
        int transPositions = 0;
 
        for (int i = 0; i < theMatchA.length(); i++)
        {
            //Look Backward
            int counter = 0;
            while(counter <= mRange && i >= 0 && counter <= i)
            {
                if (theMatchA.charAt(i) == theMatchB.charAt(i - counter) && counter > 0)
                {
                    transPositions++;
                }
                counter++;
            }
 
            //Look forward
            counter = 1;
            while(counter <= mRange && i < theMatchB.length() && (counter + i) < theMatchB.length())
            {
                if (theMatchA.charAt(i) == theMatchB.charAt(i + counter) && counter > 0)
                {
                    transPositions++;
                }
                counter++;
            }
        }
        return transPositions;
    }
 
    private int getCommonPrefix(String compOne, String compTwo)
    {
        int cp = 0;
        for (int i = 0; i < 4; i++)
        {
            if (compOne.charAt(i) == compTwo.charAt(i)) cp++;
        }
        return cp;
    }
    
    public static void main(String[] args) {
		Jaro j = new Jaro();
		double similarity = j.getSimilarity("jame", "janes");
		System.out.println(similarity);
	}
}
